<?php
		require("../dbconnect.php");
		require("../function.php");

		$month=$_GET['month'];
		$year=$_GET['year'];
			
		
	

		if($year!=date("Y") || $month!=date("m"))
		{
			$lastday=date("t",mktime(0,0,0,$month+1,0,$year));
		}
		else
		{
			$lastday=date("d");
		}
		
		$dayArr="";
		$totalArr="";
		$maxValue=0;
		$noArr="";
		$preCount=0;
		
		for($i=1;$i<=$lastday;$i++)
		{
			$dayArr.=$i."|";
			
			$getDay=$year."-".$month."-".$i;
			
			$get_visitor=mysql_query("select * from os_totalvisit where visit_date='$getDay'")or die(mysql_error());
			
			
			if(mysql_num_rows($get_visitor)==0)
			{
				$totalArr.="0|";
				$noArr.="0,";
			}
			else
			{
				if($maxValue<mysql_result($get_visitor,0,"total_visit"))
				{
					$maxValue=mysql_result($get_visitor,0,"total_visit");
				}
				//insert into array then sort!!!!
				$noArr.=mysql_result($get_visitor,0,"total_visit").",";
			}
			
		}
		
		
		$totalArr="0|".round($maxValue/2,0)."|".$maxValue." visitor(s)";
?>		
	<table>
		<tr valign="top">
			<td colspan="3">
			<br>
			<div class="sub_title">Daily visitor statistic for <?= date("M",mktime(0,0,0,$month+1,0,$year)) ?> <?= $year ?></div>
			<br><br>
			<img src="http://chart.apis.google.com/chart?cht=lc&amp;chs=600x200&amp;chd=t:<?= rtrim($noArr,",") ?>&amp;chds=0,<?= $maxValue ?>&amp;chxt=x,y&amp;chxl=0:|<?= $dayArr ?>1:|<?= rtrim($totalArr,"|") ?>" alt="Daily visitor statistic for <?= date("M Y") ?>" />
			</td>
		</tr>
		<tr>
			<Td colspan="3"><hr style=" height:1px; color:#000000"></Td>
		</tr>

		<tr>
			<td width="39%" valign="top">
				<table width="205" cellpadding="2">
					<tr class="table_header">
						<td width="89">Date</td><Td width="100">Total visitor(s)</Td>
					</tr>
					<?
						
						$get_list=mysql_query("select * from os_totalvisit where month(visit_date)='$month' and year(visit_date)='$year' order by visit_date asc")or die(mysql_error());
					
						if(mysql_num_rows($get_list)==0)
						{
					?>
					<tr>
						<td colspan="2" align="center"> no record</td>
					</tr>
					<?
						}else{
						
						$no=0;
						$total=0;
						while($d=mysql_fetch_array($get_list,MYSQL_ASSOC)){
							if($no%2==0)
							{
								$bgcolor="#e5e5e5";
							}
							else
							{
								$bgcolor="#eeeeee";	
							}
							$total=$total+$d['total_visit'];
					?>
					<tr height="20" bgcolor="<?= $bgcolor ?>" onmouseover="this.style.backgroundColor='ccccff'" onmouseout="this.style.backgroundColor='<?= $bgcolor ?>'">
						<td><?= $d['visit_date'] ?></td><td align="center"><?= $d['total_visit'] ?></td>
					</tr>
					<? $no++; } ?>
					<tr style="background-color:#999999;color:#FFFFFF">
						<Td> Total </Td><Td align="center"><?= $total ?></Td>
					</tr>
					<? } ?>
					
			  </table>
			</td>
			<td width="16%">&nbsp; </td>
			<td width="45%" valign="top">
				<div class="sub_title">Monthly Visitor Statistic for Year <?= $year ?></div>
				<br>
				<? 
					$monthArr="";
					$monthTotalArr="";
					$maxMonth=0;
					
					for($m=1;$m<13;$m++){
					
					 	$monthArr.=date("M",mktime(0,0,0,$m+1,0,date("Y")))."|";
						
						$getTotal=mysql_query("select sum(total_visit) as result from os_totalvisit where month(visit_date)=$m and year(visit_date)=$year");
						
						if($maxMonth<mysql_result($getTotal,0,"result"))
						{
							$maxMonth=mysql_result($getTotal,0,"result");
						}
						
						if(mysql_result($getTotal,0,"result")!="" || mysql_result($getTotal,0,"result")>0)
						{
							$monthTotalArr.=mysql_result($getTotal,0,"result").",";
						}else{
							$monthTotalArr.="0,";
						}
						
						
					}
					$totalArr="0|".round($maxMonth/2,0)."|".$maxMonth." visitor(s)";										
				?>
				
				<img src="http://chart.apis.google.com/chart?chs=420x200&amp;cht=bvs&amp;chds=0,<?= $maxMonth ?>&amp;chd=t:<?= rtrim($monthTotalArr,",") ?>&amp;chxt=x,y&amp;chxl=0:|<?= $monthArr ?>1:|<?= rtrim($totalArr,"|") ?>"/>
				
			</td>
		</tr>
</table>